/*
 * BaseDAO
 * Version: 1.0
 * Date: 24/07/2014
 * 
 * Copyright: ThoNQ
 * 
 * Modification Logs:
 * DATE             AUTHOR              DESCRIPTION
 * ==================================================
 * 24/07/2014       ThoNQ               Create
 */

package model.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

import common.GlobalConstant;


/**
 * @Description: All class have connect to database, its must be extend from this class
 * @author Fresher186
 * @version 24/07/2014
 */
public class BaseDAO {
    private Connection connection;
    
    /**
     * Get connect to database
     * @return Connection
     */
    public Connection getConnection(){
        try {
            
            // Registration  driver
            Class.forName(GlobalConstant.DRIVER);
            
            // Create connection

                connection = DriverManager.getConnection(GlobalConstant.CONNECTION_STRING,
                                                        GlobalConstant.USERNAME,
                                                        GlobalConstant.PASSWORD);

        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        }
        finally{
        }
        return connection;
    }
    
    /**
     * close connection
     */
    public void closeConnection(){
        try {
            connection.close();
        } catch (SQLException e) {
        }
    }
    
}
